package com.team.book.web;

import com.team.book.common.domain.Page;
import com.team.book.common.domain.ResponseEntity;
import com.team.book.domain.BorrowedRecord;
import com.team.book.service.BorrowedRecordService;
import com.team.book.web.dto.BorrowedRecordDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 图书
 * @author Joann
 *
 */
@RestController
@RequestMapping(value = "/api/book/")
public class BorrowedRecordController {
	
	@Autowired
	public BorrowedRecordService recordService;

    @GetMapping(value = "/borrowed-record")
    public ResponseEntity<Page<BorrowedRecord>> query(Page<BorrowedRecord> page, BorrowedRecordDTO record){
    	Page<BorrowedRecord> recordPage = recordService.query(page,record);
        return ResponseEntity.ok(recordPage);
    }


    @RequestMapping(value = "/borrowed-record",method = RequestMethod.DELETE,produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Void> del(@RequestBody BorrowedRecord record){
        int num = recordService.del(record.getId());
        if(num>0){
            return ResponseEntity.ok();
        }
        return ResponseEntity.fail();

    }
}
